package com.pets.springboot_petshop.controller;

import com.pets.springboot_petshop.entity.Orderproduct;
import com.pets.springboot_petshop.pojo.Result;
import com.pets.springboot_petshop.service.OrderproductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: wxk
 * @Email: 2089967794@qq.com
 * @Date: 2024/10/15 下午2:54 周二
 * @Description: s
 */
@RestController
@RequestMapping("/Orderproduct")
public class OrderproductController {
    @Autowired
    private OrderproductService orderproductService;
    //user_id查询
    @GetMapping("selectorder_id")
    private Result selectorder_id(@RequestParam int order_id) {
        List<Orderproduct> orderproduct = orderproductService.selectorder_id(order_id);
        if (orderproduct != null) {
            return Result.success(orderproduct);
        }else {
            return Result.error("获取失败");
        }
    }
    //查询所有
    @GetMapping("/findAll")
    private Result findAll() {
        List<Orderproduct> orderproduct = orderproductService.findAll();
        if(orderproduct == null || orderproduct.isEmpty()){
            return Result.error("获取失败");
        }else {
            return Result.success(orderproduct);
        }
    }
    //添加
    @PostMapping("add")
    private Result add(@RequestBody Orderproduct orderproduct) {
        if (orderproductService.add(orderproduct)>0){
            return Result.success("新增成功");
        }else {
            return Result.error("获取失败");
        }
    }

    //删除
    @PostMapping("delete")
    private Result delete(@RequestParam Integer id){
        if (orderproductService.delete(id)>0){
            return Result.success("删除成功");
        }else {
            return Result.error("删除失败");
        }
    }
    //修改数据
    @PostMapping("update")
    private Result update(@RequestBody Orderproduct orderproduct){
        if (orderproductService.update(orderproduct)>0){
            return Result.success("修改成功");
        }else {
            return Result.error("修改失败");
        }
    }
}
